package com.xbongbong.pro.workorder.pojo.dto;

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.pro.user.pojo.ReturnUserAndDepartmentPojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/4/19 14:50
 * @since v1.0
 */
@Getter
@Setter
@ToString
public class ChangeWorkflowDTO extends BaseDTO {
    private static final long serialVersionUID = 793829999230039301L;

    /**
     * 工单id
     */
    @NotNull(message = "{dto.msg.changeWorkflow.workOrderId.NotNull}")
    private Long workOrderId;
    /**
     * 负责人
     */
    private ReturnUserAndDepartmentPojo user;
    /**
     * 协同人
     */
    private List<ReturnUserAndDepartmentPojo> coUser;
    /**
     * 下一阶段id
     */
    private ItemPoJo nextStageId;
    /**
     * 操作类型
     */
    @NotNull(message = "{dto.msg.changeWorkflow.operate.NotNull}")
    private String operate;
    /**
     * 完成、转派、回退、关闭、重启时填写
     */
    @Size(max = 2000,message = "{dto.msg.changeWorkflow.memo.Size}")
    private String memo;

    public void setUser(Object userObj) {
        try {
            this.user = JSON.parseObject(JSON.toJSONString(userObj),ReturnUserAndDepartmentPojo.class);
        }catch (Exception e){
            this.user = new ReturnUserAndDepartmentPojo();
        }
    }
}
